package com.lsmgc.cms.service.poster;

import com.lsmgc.cms.constant.SysConstant;
import com.lsmgc.cms.dao.poster.PosterDao;
import com.lsmgc.cms.entity.poster.Poster;
import com.lsmgc.cms.entity.poster.PosterQuery;
import com.lsmgc.cms.util.page.Pagination;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PosterService {
    private PosterDao posterDao = new PosterDao();

    public boolean addPoster(Poster poster) throws SQLException {
        int n = posterDao.addPoster(poster);
        if (n>0) {
            return true;
        }
        return false;
    }

    public Pagination getPosterListPage(PosterQuery posterQuery) throws SQLException {
        Pagination pagination = new Pagination(posterQuery.getPageNo(), posterQuery.getPageSize(), posterDao.getPosterListPageCount(posterQuery).intValue());
        List<Poster> list = posterDao.getPosterListPage(posterQuery);
        if (list ==null) {
            list = new ArrayList<>();
        }
        pagination.setList(list);
        return pagination;
    }

    public Poster getPosterById(Long id) throws SQLException {
        return posterDao.getPosterById(id);
    }

    public boolean updatePosterById(Poster poster) throws SQLException {
        int n = posterDao.updatePosterById(poster);
        if (n>0) {
            return true;
        }
        return false;
    }

    public boolean deletePosterById(Long id) throws SQLException {
        int n = posterDao.deletePosterById(id);
        if (n>0) {
            return true;
        }
        return false;
    }
}
